{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "## Step 1: Authentication\n",
    "\n",
    "The first step is to initialize a GsSession with your application ID. For more information on how to create and register an application, check this [tutorial](https://developer.gs.com/p/docs/institutional/platform/getting-started/). In the snippet below, substitute client_id and client_secret with your application ID and secret respectively."
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "c6b8ac530007ea21"
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "from gs_quant.session import GsSession, Environment\n",
    "GsSession.use(Environment.PROD, client_id=None, client_secret=None)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-08-20T20:55:42.569859800Z",
     "start_time": "2024-08-20T20:55:39.923882800Z"
    }
   },
   "id": "db1c365daf064da"
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Step 2: Define parameters\n",
    "\n",
    "Next, we import all required modules and define required parameters:\n",
    "\n",
    "1. **The Dataset ID**: S3_PARTNERS_EQUITY_SHORT_INTEREST\n",
    "2. **A time range** \n",
    "3. **A list of assets** to query data for"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "dcd6b4e12461dea8"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "from gs_quant.data import Dataset\n",
    "import datetime as dt\n",
    "\n",
    "dataset_id = \"S3_PARTNERS_EQUITY_SHORT_INTEREST\"\n",
    "\n",
    "dataset = Dataset(dataset_id)\n",
    "start_date = dt.date(2024, 5, 1)\n",
    "end_date = dt.date(2024, 8, 1)\n",
    "bbids = [\"META UW\", \"NVDA UW\", \"AAPL UW\", \"MSFT UW\", \"AMZN UW\", \"GOOG UW\", \"TSLA UW\"]"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "b35aecebdb1a47d9"
  },
  {
   "cell_type": "markdown",
   "source": [
    "**Tip**: You can use the get_coverage function to see the full list of equity securities for which there is data:"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "dbe6305116d93bac"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "coverage = dataset.get_coverage()"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "291c364a533d9dc"
  },
  {
   "cell_type": "markdown",
   "source": [
    "### Step 3: Get data\n",
    "\n",
    "Now, it's time to get data. We will just have to plug in the parameters we defined above\n",
    "\n",
    "1. **start**: The start date for the query\n",
    "2. **end**: The end date for the query\n",
    "3. **bbid**: Bloomberg IDs of assets.  "
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "1361ea71b49d9289"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "s3_data = dataset.get_data(start=start_date, end=end_date, bbid=bbids)"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "26ce1a7acf1eb902"
  },
  {
   "cell_type": "markdown",
   "source": [
    "#### What if I want to pass in other identifiers, such as SEDOLs or ISINs instead of BBIDs? \n",
    "\n",
    "You can also pass other identifiers (such as ticker, SEDOL, ISIN, CUSIP, etc).\n",
    "\n",
    "Please note certain identifiers may be subject to licensing."
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "cb8ffba3955000af"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "s3_data = dataset.get_data(start=end_date, end=end_date, sedol=[\"2857817\", \"2206657\"])\n",
    "s3_data = dataset.get_data(start=end_date, end=end_date, isin=[\"US7134481081\", \"US5801351017\"])"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "c914b3b91cd89679"
  },
  {
   "cell_type": "markdown",
   "source": [
    "### Step 4: Get individual fields\n",
    "\n",
    "You many also want to query a timeseries for a subset of fields in the dataset. Below is a 3-months timeseries daily short interest and short interest percent data for a group of stocks."
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "703802dc2f6a0ec6"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "daily_short_interest = dataset.get_data(start=start_date,\n",
    "                                        end=end_date,\n",
    "                                        bbid=bbids,\n",
    "                                        fields=[\"dailyShortInterest\", \"shortInterestPercent\"])"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "6eed59910d32b3"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
